<?php
//登录
if(!defined('IN_T')){
   die('hacking attempt');
}

if(empty($_POST)){
   //todo
}
else{
   $name = Common::sfilter($_POST['name']);
   $passwd = Common::sfilter($_POST['passwd']);
   $remember = intval($_POST['remember']);
   $res['status'] = 0;
   $tongji = $Db->query("select * from ".$Base->table('admin_tongji')." where name='$name' and passwd='".Common::encrypt($passwd)."'","Row");

   if(!empty($tongji)){
       //赋值到session
       $_SESSION['tongji'] = array(
            'id' => $tongji['id'],
            'name' => $tongji['name'],
            'priv' => $Json->decode($tongji['priv']),
       );
       //7天内免登录
       if($remember==1){
            //admin_name,passwd连接加密
            $hashcode = Common::encrypt($name.Common::encrypt($passwd));
            setcookie("tongji[id]",$tongji['id'],Common::gmtime()+7*60*60*24,'/');
            setcookie("tongji[hashcode]",$hashcode,Common::gmtime()+7*60*60*24,'/');   
       }
       $res['status'] = 1;
       $res['msg']= '登录成功，跳转...';
       $res['href'] = '/'.TONGJI_PATH.'/?m=index';
   }
   else{
       $res['msg'] = '账号密码不正确';
   }
   echo $Json->encode($res);
   exit;
}
?>